/*
 * Jamus
 * Copyright (C) 2010 Jamus Team
 *
 * Jamus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Jamus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jamus.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __PLUGIN_MANAGER
#define __PLUGIN_MANAGER

#include <string>
#include <boost/property_tree/ptree.hpp>
#include "frontend/Plugin.h"
#include "backend/Plugin.h"

class PluginManager
{
public:
	PluginManager(const std::string& frontendFilename, const std::vector<std::string>& backendFilenames, const boost::property_tree::ptree& config);
	~PluginManager();

	typedef std::vector<frontend::Plugin*> FrontendList;

	backend::Plugin& getBackend();
	FrontendList getFrontends();

private:
	struct FrontendPlugin {
		frontend::Plugin* frontend;
		void* lib;
		frontend::destroy_p* destroyHandler;
	};

	struct BackendPlugin {
		backend::Plugin* backend;
		void* lib;
		backend::destroy_p* destroyHandler;
	};

	BackendPlugin backend;
	std::vector<FrontendPlugin> frontends;

	void loadBackend(const std::string& filename, const boost::property_tree::ptree& config);
	void loadFrontends(const std::vector<std::string>& filenames, const boost::property_tree::ptree& config, backend::Plugin& backend);
};

#endif
